package cn.jt.service;

import cn.jt.dao.RightsDao;
import cn.jt.pojo.Rights;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RightsSeriveImpl implements  RightsSerive{

    @Resource
    RightsDao rightsDao;
    @Override
    public List<Rights> getRightsList() {
        QueryWrapper<Rights> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0);
        List<Rights> oneList=rightsDao.selectList(queryWrapper);
        for(Rights rights:oneList){
            queryWrapper.clear();
            queryWrapper.eq("parent_id", rights.getId());
            List<Rights> children=rightsDao.selectList(queryWrapper);
            rights.setChildren(children);
        }
        return oneList;
    }


}
